﻿@model RegisterModel
@{
    Layout = "~/Views/Shared/_ClearnLayout.cshtml";
    ViewBag.Title = Html.Global("Install_SetupAdminAccounts");
}
@functions{
    public string _Loc(string key)
    {
        var _result = HttpContext.GetGlobalResourceObject("language", key) as string;
        if (!string.IsNullOrEmpty(_result))
            return _result;
        else
            return key;
    }
}
@section NavSection
{
    <div style="display: block;">
        <ul id="sequence">
            <li><span>1</span>@Html.Global("RES_PREPARING")</li>
            <li>&gt;</li>
            <li class="d-current"><a href="#"><span>2 </span>@Html.Global("Install_Setup_AdminAccount")</a></li>
            <li>&gt;</li>
            <li><span>3 </span>@Html.Global("Install_Setup_TopSite")</li>
        </ul>
    </div>
}
<section>
    <header class="d-section">
        <span>@Html.Global("Install_Domain_Check")</span><hr />
    </header>
    <div>
        @{
            var canGoNext = false;
            if (DnaConfig.TestDomainIsChanged(Context) && DnaConfig.DnaHash > 0)
            { 
            <div>
                @MvcHtmlString.Create(Html.Global("Install_Domain_Changed"))
            </div>
            }
            else
            {
                var roles = Roles.GetAllRoles();

                if (roles.Length == 0)
                {
                    Roles.CreateRole("administrators");
                    Roles.CreateRole("guests");
                    roles = Roles.GetAllRoles();
                }
            <p>
                @Html.Global("RES_SYS_ROLES")：@string.Join(",", roles)</p>
            }
     
            <table>
                <tr>
                    <td>
                        @Html.Global("Install_TopSite_Owner"):
                    </td>
                    <td>
                        @{
                            var administrators = Roles.GetUsersInRole("administrators");
                            if (administrators.Length > 0)
                            {
                                canGoNext = true;
                            @Ajax.Dna().ComboBox("cbAdmin").Bind(administrators).DropDownList().Select(administrators[0]).GetHtml()
                            }
                        }
                    </td>
                </tr>
            </table>
   
        }
    </div>
</section>
<section>
    <header class="d-section">
        <span>@Html.Global("Install_Register_NewAdministrator")</span><hr />
    </header>
    @using (Html.BeginForm())
    {
        @Html.ValidationSummary() 
        <table>
            <tr>
                <td colspan="3">
                    <div style="padding: 5px;" class="ui-state-highlight ui-corner-all">
                        <span style="float: left; margin-right: 0.3em;" class="ui-icon ui-icon-info"></span>
                        @string.Format(_Loc("Account_Register_PasswordLength"), Html.Encode(ViewData["PasswordLength"]))
                    </div>
                </td>
            </tr>
            <tr>
                <td style="white-space: nowrap;">
                    <label for="UserName">
                        @_Loc("RES_USER_NAME"):</label>
                </td>
                <td>
                    @{ Ajax.Dna().TextBox("UserName")
                                  .Width(300)
                                  .Value(Model != null ? Model.UserName : "")
                                  .IconImageUrl(Url.Content("~/content/images/icon_contact_16.gif"))
                                  .HtmlAttributes(Html.GetUnobtrusiveValidationAttributes("UserName"))
                                  .Render();
                    }
                </td>
                <td>@Html.ValidationMessageFor(m => m.UserName, "*")
                </td>
            </tr>
            <tr>
                <td style="white-space: nowrap;">
                    <label for="Email">
                        @_Loc("RES_EMAIL"):</label>
                </td>
                <td>
                    @{Ajax.Dna().TextBox("Email")
                                  .Width(300)
                                  .Value(Model != null ? Model.Email : "")
                                  .HtmlAttributes(Html.GetUnobtrusiveValidationAttributes("Email"))
                                  .IconImageUrl(Url.Content("~/content/images/icon_mail_16.png"))
                                  .Render();
                    }
                </td>
                <td>
                    @Html.ValidationMessageFor(m => m.Email, "*")
                </td>
            </tr>
            <tr>
                <td style="white-space: nowrap;">
                    <label for="password">
                        @_Loc("RES_PASSWORD"):</label>
                </td>
                <td>
                    @{
                      Ajax.Dna().TextBox("Password")
                          .Password()
                          .Value(Model != null ? Model.Password : "")
                          .Width(300)
                          .HtmlAttributes(Html.GetUnobtrusiveValidationAttributes("Password"))
                          .IconImageUrl(Url.Content("~/content/images/icon_key_16.gif"))
                          .Render();
                    }
                </td>
                <td>@Html.ValidationMessageFor(m => m.Password, "*")
                </td>
            </tr>
            <tr>
                <td style="white-space: nowrap;">
                    <label for="ConfirmPassword">
                        @_Loc("RES_CONFIRM_PASSWORD"):</label>
                </td>
                <td>
                    @{
                      Ajax.Dna().TextBox("ConfirmPassword")
                          .Password()
                          .Value(Model != null ? Model.ConfirmPassword : "")
                          .Width(300)
                          .HtmlAttributes(Html.GetUnobtrusiveValidationAttributes("ConfirmPassword"))
                          .IconImageUrl(Url.Content("~/content/images/icon_accept_16.png"))
                          .Render();
                    }
                </td>
                <td>@Html.ValidationMessageFor(m => m.ConfirmPassword, "*")
                </td>
            </tr>
            <tr>
                <td colspan="3" style="text-align: right;">
                    @{
                      Ajax.Dna().Button()
                          .Text(_Loc("RES_REGISTER"))
                          .Options(opts => { opts.IsSubmitButton = true; })
                          .ImageIcons(Url.Content("~/content/images/icon_add_16.png"))
                          .Render();
                    }
                </td>
            </tr>
        </table>
    }
</section>
<hr />
<ul class="d-horizontal-list" style="padding: 10px; text-align: right;">
    <li>@Ajax.Dna().Link(Html.Global("RES_HELP"), Url.Help(11), Url.Content("~/content/images/help.png")).Options(opts => { opts.Target = "_blank"; }).GetHtml()</li>
    <li>@Ajax.Dna().Button().LocText("RES_PREVIOUS").ImageIcons(Url.Content("~/content/images/icon_back_16.png")).Click("location=\"" + Url.Action("Index") + "\";").GetHtml()</li>
    @if (canGoNext)
    {
        <li>@Ajax.Dna().Button().LocText("RES_NEXT").ImageIcons(Url.Content("~/content/images/icon_next_16.png")).Click("location=\"" + Url.Action("CreateWeb") + "/\"+$(\"#cbAdmin\").val();").GetHtml()</li>
    }
</ul>
